function Player(id, name, inheritedDebt, otherPayments) {
   this.id = id;
   this.name = name;
   this.inheritedDebt = inheritedDebt;
   this.otherPayments = otherPayments;
   this.toString = function () {
      return id + "," + name + "," + inheritedDebt + "," + otherPayments;
   }
}

function PlayerPayment(game, player, payment, charged) {
   this.game = game;
   this.player = player;
   this.payment = payment;
   this.charged = charged;
   this.toString = function () {
      return game.date + "," + player.name + "," + payment + "," + charged;
   }
}

function createPlayerPayment(game, player, payment, charged) {
   return new PlayerPayment(game, player, payment, charged);
}

function Game(id, date, price, payments) {
   this.id = id;
   this.date = date;
   this.price = price;
   this.payments = payments;
   this.toString = function () {
      return id + "," + date + "," + price + "," + payments;
   }
}

function createFootyDB () {
   var data = getFootyData();
   var players = [];
   var games = [];
   // convert players array data into Player objects
   data.players.each(function (playerData) {
      players.push(new Player(playerData[0], playerData[1], playerData[2], playerData[3]));
   });
   // convert games array data into Game objects
   data.games.each(function (gameData) {
      // convert payments array data into PlayerPayment objects
      var game_id = gameData[0];
      var game_date = gameData[1];
      var game_price = gameData[2];
      var game_payments = gameData[3];
      var payments = game_payments.collect(function (paymentData) {
         var payment_game_id = paymentData[0];
         var payment_player_id = paymentData[1];
         var payment_payment = paymentData[2];
         var payment_charged = paymentData[3];
         return createPlayerPayment(payment_game_id, players[payment_player_id], payment_payment, payment_charged);
      });
      games.push(new Game(game_id, game_date, game_price, payments));
   });
   return {'players': players, 'games': games};
}